﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace XGameLibrary
{
    public class World : DrawableGameComponent
    {
        #region Graphic Field and Property Region

        #endregion

        #region Item Field and Property Region
        Texture2D background;

        //ItemManager itemManager = new ItemManager();

        #endregion

        #region Level Field and Property Region

        //readonly List<Level> levels = new List<Level>();
        //int currentLevel = -1;

        //public List<Level> Levels
        //{
        //    get { return levels; }
        //}

        //public int CurrentLevel
        //{
        //    get { return currentLevel; }
        //    set
        //    {
        //        if (value < 0 || value >= levels.Count)
        //            throw new IndexOutOfRangeException();

        //        if (levels[value] == null)
        //            throw new NullReferenceException();

        //        currentLevel = value;
        //    }
        //}
        private static int cellSize;
        public static int CellSize
        {
            get
            {
                return cellSize;
            }
        }


        private static int mapWidth;
        private static int mapHeight;
        public static int MapWidth
        {
            get
            {
                return mapWidth;
            }
        }

        public static int MapHeight
        {
            get
            {
                return mapHeight;
            }
        }

        #endregion

        #region Constructor Region

        public World(Game game, Texture2D background, int cellSize)
            : base(game)
        {
            this.background = background;
            World.cellSize = cellSize;
            mapWidth = background.Width;
            mapHeight = background.Height;

        }

        #endregion

        #region Method Region

        public override void Update(GameTime gameTime)
        {
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
        }

        public void DrawLevel(GameTime gameTime, SpriteBatch spriteBatch, Camera camera)
        {
            //if (InputHandler.ScreenWidth / camera.Zoom > background.Width)
            //    camera.SetZoom(InputHandler.ScreenWidth / background.Width);
            //if (InputHandler.ScreenHeight / camera.Zoom > background.Height)
            //    camera.SetZoom(InputHandler.ScreenHeight / background.Height);
            Vector2 cameraPoint = camera.Position;
            spriteBatch.Draw(this.background, new Rectangle(0, 0, InputHandler.ScreenWidth, InputHandler.ScreenHeight), new Rectangle((int)cameraPoint.X, (int)cameraPoint.Y, (int)(InputHandler.ScreenWidth / camera.Zoom), (int)(InputHandler.ScreenHeight / camera.Zoom)), Color.White);
        }

        #endregion
    }
}
